/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dispositivos;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import baseDeDatos.*;
    
/**
 *
 * @author 66880774
 */
public class Fichero implements Dispositivo {

    @Override
    public String leer(String... ruta) {
        
        String resultado ="";
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream (ruta[0])));
            
            String line;
            
            while((line = br.readLine()) != null) resultado += line + "\n"; //lee linea a linea y termina cuando sea null.
            
        } catch (IOException ex) {
            Logger.getLogger(Fichero.class.getName()).log(Level.SEVERE, null, ex);//lo pone automaticamente.
        }
        return resultado;
    }
 
    public void escribir( String contenido, String... ruta ) {
        try {
            BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (ruta[0])));
          
            bw.write(contenido);
            
        } catch (IOException ex) {
           ex.printStackTrace(System.err);
        }
    }
   }

